#include "Font.h"

namespace TSS
{

	Font::Font(std::string name, int pointSize)
	{
		fontObj = NULL;

		D3DXFONT_DESC desc = {
			pointSize,
			0,
			0,
			0,
			false,
			DEFAULT_CHARSET,
			OUT_TT_PRECIS,
			CLIP_DEFAULT_PRECIS,
			DEFAULT_PITCH,
			""
		};

		strcpy(desc.FaceName, name.c_str());

		D3DXCreateFontIndirect(g_engine->getDevice(), &desc, &fontObj);
	}

	Font::~Font()
	{
		fontObj->Release();
	}

	void Font::Print(int x, int y, std::string text, D3DCOLOR color)
	{
		RECT rect = { x, y, 0, 0 };
		fontObj->DrawTextA(NULL, text.c_str(), text.length(), &rect, DT_CALCRECT, color);

		fontObj->DrawTextA(g_engine->getSpriteObj(), text.c_str(), text.length(), &rect, DT_LEFT, color);
	}

	int Font::getTextWidth(std::string text)
	{
		RECT rect = {0, 0, 0, 0};
		fontObj->DrawTextA(NULL, text.c_str(), text.length(), &rect, DT_CALCRECT, 0xffffffff);
		return rect.right;
	}

	int Font::getTextHeight(std::string text)
	{
		RECT rect = {0, 0, 0, 0};
		fontObj->DrawTextA(NULL, text.c_str(), text.length(), &rect, DT_CALCRECT, 0xffffffff);
		return rect.bottom;
	}

};